package edu.ucsd.cs110.mycity;

import java.util.ArrayList;

import android.graphics.drawable.Drawable;
import android.location.Location;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;

import edu.ucsd.cs110.mycity.controller.ViewController;

public class MyOverlay extends BalloonItemizedOverlay<OverlayItem> {

	private ArrayList<OverlayItem> overlayItem = new ArrayList<OverlayItem>();
	private Location currentLocation;

	public MyOverlay(Drawable defaultMarker, MapView mapView) {
	    super(boundCenter(defaultMarker),mapView);
	    boundCenter(defaultMarker);
	}
	
	@Override
	protected OverlayItem createItem(int i) {
	    // TODO Auto-generated method stub
	    return overlayItem.get(i);
	}
	
	@Override
	public int size() {
	    return overlayItem.size();
	}
	
	public void addOverlay(OverlayItem overlay) {
	    overlayItem.add(overlay);
	    populate();
	}
	
	@Override
	public boolean onTap(GeoPoint arg0, MapView arg1) {
		MyCityMapActivity mapActivity = (MyCityMapActivity) ViewController.getMapScreen();
		if ( mapActivity.setFavorite() ) {
			mapActivity.addPin(arg0);
			mapActivity.flipFavorite();
		}
		return super.onTap(arg0, arg1);
	}
	
	@Override
	protected boolean onBalloonTap(int index, OverlayItem item) {
	    return true;
	}

	public void setCurrentLocation(Location currentLocation) {
		this.currentLocation = currentLocation;
	}

	public Location getCurrentLocation() {
		return currentLocation;
	}

}
